package operation;
import java.util.Scanner;
import book.BookList;
import book.Book;
public class ReturnOperation implements IOperation{
    public void work(BookList bookList) {
        int currentSize = bookList.getUsedSize();
        System.out.println("归还图书");
        System.out.println("请输入归还图书的名字");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();
        Book book;
        for (int i = 0; i < currentSize; i++) {
            book = bookList.getBooks(i);
            if(!(book.isBorrowed()) && book.getName().equals(name)) {
                System.out.println("这本书未借出，归还失败");
                return;
            }
            if(book.getName().equals(name)) {
                System.out.println("归还成功");
                book.setBorrowed(false);
                return;
            }
        }
        System.out.println("没有找到这本书的信息，请确认图书馆内是否有这本书");
    }
}